package com.projectdemo.springbootdemo1.service;

import com.projectdemo.springbootdemo1.dao.DepartmentRepository;
import com.projectdemo.springbootdemo1.pojo.Department;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collection;

@Service
public class DepartmentService {

    @Autowired
    private DepartmentRepository departmentRepository;

    public Iterable<Department> getAllDepartments() {
        return departmentRepository.findAll();
    }

    public Department getDepartmentById(Integer id) {
        return departmentRepository.findById(id).orElse(null);
    }

    public Department saveDepartment(Department user) {
        return departmentRepository.save(user);
    }

    public void deleteDepartment(Integer id) {
        departmentRepository.deleteById(id);
    }
}
